package com.college.resource.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.college.common.pojo.ao.Notice;
import com.college.common.pojo.dto.resource.AddNoticeDTO;
import com.college.common.pojo.dto.resource.QueryNoticeDTO;
import com.college.common.pojo.dto.resource.UpdateNoticeDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.resource.mapper.NoticeMapper;
import com.college.resource.service.NoticeService;
import com.github.pagehelper.page.PageMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 公告 服务实现类
 * @author 小C工作室
 * @since 2025-02-22
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public List<Notice> queryList(QueryNoticeDTO queryNoticeDTO) {
        return noticeMapper.queryList(queryNoticeDTO);
    }

    @Override
    public List<Notice> queryListPage(QueryNoticeDTO queryNoticeDTO, PageParamRequest pageParamRequest) {
        PageMethod.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        return noticeMapper.queryList(queryNoticeDTO);
    }

    @Override
    public CommonResult<String> addNotice(AddNoticeDTO addNoticeDTO) {
        return this.save(addNoticeDTO)? CommonResult.success("公告新增成功") : CommonResult.failed("公告新增失败");
    }

    @Override
    public CommonResult<String> updateNotice(UpdateNoticeDTO updateNoticeDTO) {
        Notice notice = ObjectUtil.objectCopyProperties(updateNoticeDTO, Notice.class);
        return this.updateById(notice) ? CommonResult.success("公告修改成功") : CommonResult.failed("公告修改失败");
    }
}
